<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class PageController extends CommonController {


	//单页信息列表
	public function index(){
        $lis=M('page');
		$list=$lis->select();

	    foreach ($list as $key => $value) {

        $list[$key]['intro']=mb_substr(strip_tags(htmlspecialchars_decode($value['intro'])),0,20,'utf-8');

       print_r(  $list[$key]['intro']);
       die();
        }


	
		$this->assign('list',$list);




		$this->display();
	}



	public function delete(){

		$id=I('get.id');

		if ($id) {

			M('pages')->where(array('id'=>$id))->delete();
			$this->success('删除成功');
		}








	}


	public function add(){

		if (IS_POST) {
			$data=array();
            $data['name'] = I('post.name');
			$data['intro']=I('post.intro');
			$data['edittime']=time();


			if(M('pages')->add($data)){
				$this->success('信息添加成功',U('Page/jindex'));
				exit();
			}else{
				$this->success('信息添加失败',U('Page/jindex'));
				exit();
			}
		}




		$this->display();
	}


	public function jindex(){
        $lis=M('pages');
		$list=$lis->select();

	    foreach ($list as $key => $value) {

        $list[$key]['intro']=mb_substr(strip_tags(htmlspecialchars_decode($value['intro'])),0,20,'utf-8');

     
        }


	
		$this->assign('list',$list);




		$this->display();
	}



    public function edit(){

		$lis=M('pages');
		$id=I('get.id');
		$lists=$lis->where(array('id'=>$id))->find();

        $lists['intro'] = html_entity_decode($lists['intro']);
		$this->assign('info',$lists);

		//所属分类

		
		if (IS_POST) {
			$data=array();

			$data['intro']=stripcslashes(I('post.intro'));
			
            $data['name'] = I('post.name');

			if(M('pages')->where(array('id'=>$id))->save($data)){
				$this->success('单页信息修改成功',U('Page/jindex'));
				exit();
			}else{
				$this->success('单页信息修改失败',U('Page/jindex'));
				exit();
			}
		}




		$this->display();





    }


}
?>